﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iSun.Entity;
using iSun.Model;

namespace iSun.SYS.Bussiness.Phrase
{
    public partial class BDatPhraseClass : BLL.Base.BaseBussnies<DatPhraseClass>
    {
        public BDatPhraseClass() { this.entity = new DatPhraseClass(); }

        /// <summary>
        /// 通过ClassID获取PhraseClass实例
        /// </summary>
        /// <param name="ClassID"></param>
        /// <returns></returns>
        public DatPhraseClass GetDatPhraseClassByID(Guid ClassID)
        {
            return this.GetEntityById<DatPhraseClass>(ClassID);
        }

        /// <summary>
        /// 获取所有没有停用PhraseClass实例
        /// </summary>
        /// <param name="ClassValue"></param>
        /// <returns></returns>
        public IList<DatPhraseClass> GetAllDatPhraseClass(string ClassValue)
        {
            return this.GetEntityListByCondition<DatPhraseClass>("IsPause=0");
        }

        /// <summary>
        /// 通过ClassValue获取PhraseClass实例
        /// </summary>
        /// <param name="ClassValue"></param>
        /// <returns></returns>
        public DatPhraseClass GetDatPhraseClassByClassValue(string ClassValue)
        {
            return this.GetEntityByCondition<DatPhraseClass>("ClassValue='" + ClassValue + "' and IsPause=0");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        public override string CheckData(BaseEntity instance)
        {
            DatPhraseClass entity = instance as DatPhraseClass;
            if (string.IsNullOrEmpty(entity.ClassValue))
            {
                return "字典类型值不能为空!";
            }
            if (IsExeists(entity))
            {
                return "该字典类型己存在!";
            }
            return base.CheckData(entity);
        }

        public override string CheckData()
        {
            return CheckData(this.entity);
        }

        public bool IsExeists(DatPhraseClass entity)
        {
            return GetEntitysByCondition("ClassValue ='" + entity.ClassValue + "'") != null;
        }

    }
}
